package com.mall.goods.controller;


import com.mall.goods.model.CategoryBrand;
import com.mall.goods.service.ICategoryBrandService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.mall.common.util.RespResult;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;


/**
 * <p>
 * 品牌分类关联表 控制器
 * </p>
 *
 * @author Darren
 * @since 2022-08-18
 */
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@Api(tags = "REST - 品牌分类关联表")
@RestController
@RequestMapping("/category-brand")
public class CategoryBrandController {
    private final ICategoryBrandService service;

    @PostMapping("/addCategoryBrand")
    @ApiOperation(value = "新增")
    public RespResult addCategoryBrand(@RequestBody CategoryBrand categorybrand){
        boolean flag = service.addCategoryBrand(categorybrand);
        return RespResult.ok(flag ? "创建成功" : "创建失败");
    }

    @DeleteMapping("/delete/{categoryId}")
    @ApiOperation(value = "根据id删除")
    public RespResult deleteById(@PathVariable("categoryId") Integer categoryId){
        boolean flag = service.deleteById(categoryId);
        return RespResult.ok(flag ? "删除成功" : "删除失败");
    }

    @PutMapping("/updateCategoryBrand")
    @ApiOperation(value = "更新")
    public RespResult updateCategoryBrand(@RequestBody CategoryBrand categorybrand){
        boolean flag = service.updateCategoryBrand(categorybrand);
        return RespResult.ok(flag ? "更新成功" : "更新失败");
    }

    @GetMapping("/{categoryId}")
    @ApiOperation(value = "根据id查询")
    public RespResult getById(@PathVariable("categoryId") Integer categoryId){
        return RespResult.ok(service.getById(categoryId));
    }

    @PostMapping("/selectList")
    @ApiOperation(value = "根据条件查询全部数据")
    public RespResult selectList(CategoryBrand categorybrand){
        return RespResult.ok(service.selectList(categorybrand));
    }

    @PostMapping("/selectPage")
    @ApiOperation(value = "分页查询")
    public RespResult selectPage(Page<CategoryBrand> page, CategoryBrand categorybrand){
        return RespResult.ok(service.selectPage(page, categorybrand));
    }

}